package com.lj.dict.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.common_web.annotation.ResponseResultVo;
import com.lj.dict.param.DictPageParam;
import com.lj.dict.param.DictSaveParam;
import com.lj.dict.param.DictUpdateParam;
import com.lj.dict.result.DictInfoResult;
import com.lj.dict.result.DictItemResult;
import com.lj.dict.result.DictPageResult;
import com.lj.dict.service.DictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2025-01-10 11:07:47
 */
@RestController
@RequestMapping("/dict/dict")
@ResponseResultVo
@Tag(name = "字典表 管理")
public class DictController {

    @Resource
    private DictService dictService;

    @GetMapping("/page")
    @SaCheckPermission("dict:dict:list")
    @Operation(summary = "字典表 分页查询")
    public IPage<DictPageResult> page(@ParameterObject DictPageParam param) {
        return dictService.page(param);
    }

    @GetMapping("/info/{id}")
    @SaCheckPermission("dict:dict:info")
    @Operation(summary = "字典表 信息")
    public DictInfoResult info(@PathVariable("id") @Parameter(name = "id", description = "字典表 id") Long id) {
        if (id == null) {
            return null;
        }
        return dictService.info(id);
    }

    @PostMapping("/save")
    @SaCheckPermission("dict:dict:save")
    @Operation(summary = "字典表 新增")
    public void save(@RequestBody @Validated DictSaveParam param) {
        dictService.save(param);
    }

    @PostMapping("/update")
    @SaCheckPermission("dict:dict:update")
    @Operation(summary = "字典表 更新")
    public void update(@RequestBody @Validated DictUpdateParam param) {
        dictService.update(param);
    }

    @PostMapping("/delete")
    @SaCheckPermission("dict:dict:delete")
    @Operation(summary = "字典表 删除")
    public void delete(@RequestBody List<Long> ids) {
        dictService.delete(ids);
    }

    @GetMapping("/item")
    @Operation(summary = "根据字典类型获取字典项")
    public List<DictItemResult<Object>> getItemByName(@Parameter(description = "字典类") String dictType) {
        return dictService.getDictItemByName(dictType);
    }

}

